<template>
  <el-dialog
    v-model="dialogFormVisible"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    title="状态更新"
    width="600"
    @close="handleClose"
  >
    <!-- 查询条件 -->
    <avue-form
      :option="formOption"
      v-model="formParams"
      ref="ruleFormRef"
      v-if="formParams"
    >
      <template #menu-form="{}">
        <div class="text-right">
          <el-button @click="handleClose">取消</el-button>
          <el-button type="primary" @click="handleSave">保存</el-button>
        </div>
      </template>
    </avue-form>
  </el-dialog>
</template>
<script setup name="ProjectStatus">
import { reactive, getCurrentInstance, watchEffect } from 'vue'
import { project_status, project_phase } from '@/hooks/dict/useProject'
import * as Api from '@/api/projectManage/project'
const { proxy } = getCurrentInstance()
const props = defineProps({
  assemblyParam: {
    required: true
  }
})
const data = reactive({
  dialogFormVisible: true,
  formParams: {},
  formOption: {
    submitBtn: false,
    emptyBtn: false,
    column: [
      {
        label: '当前状态',
        prop: 'status',
        type: 'radio',
        span: 24,
        row: true,
        dicData: project_status
      },
      // {
      //   prop: 'proSchedule',
      //   label: '项目进度',
      //   placeholder: '请选择项目进度',
      //   type: 'select',
      //   span: 24,
      //     disabled:true,
      //   row: true,
      //   dicData: project_phase
      // },
      {
        prop: 'updateRemark',
        label: '更新说明',
        row: true,
        span: 24,
        placeholder: '请输入更新说明',
        type: 'textarea',
        rows: 5
      }
    ]
  }
})
const { dialogFormVisible, formParams, formOption } = toRefs(data)

watchEffect(() => {
  dialogFormVisible.value = props.assemblyParam.visible
  formParams.value.proSchedule = props.assemblyParam.proSchedule
  formParams.value.status = props.assemblyParam.status
})
// 保存
const handleSave = () => {
  proxy.$refs['ruleFormRef'].validate((valid, done, msg) => {
    if (valid) {
      let param = {
        // proSchedule: formParams.value.proSchedule,
        projectId: props.assemblyParam.projectId,
        status: formParams.value.status,
        updateRemark: formParams.value.updateRemark
      }
      Api.updateStatus(param).then(res => {
        proxy.$modal.msgSuccess('操作成功')
        handleClose()
      })
      done()
    }
  })
}
const emit = defineEmits(['close'])
// 取消
function handleClose() {
  dialogFormVisible.value = false
  emit('close', 'status')
}
</script>
